layui.config({
    base: $config.resUrl + '/web/common/js/'//定义基目录
}).extend({
    ajaxExtention: 'ajaxExtention', //加载自定义扩展
    $tool: 'tool',
    $api: 'api'
}).use(['form', 'layer', 'ajaxExtention', '$tool', '$api'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        $ = layui.jquery,
        $tool = layui.$tool,
        $api = layui.$api;

    //video背景
    $(window).resize(function () {
        if ($(".video-player").width() > $(window).width()) {
            $(".video-player").css({
                "height": $(window).height(),
                "width": "auto",
                "left": -($(".video-player").width() - $(window).width()) / 2
            });
        } else {
            $(".video-player").css({
                "width": $(window).width(),
                "height": "auto",
                "left": -($(".video-player").width() - $(window).width()) / 2
            });
        }
    }).resize();

    //登录按钮事件
    form.on("submit(login)", function (data) {
        // console.log(data.field);
        var req = {
            username: data.field.username,
            password: data.field.password,
            type: data.field.type
        };
        var url = $tool.getContext() + '/login';
        $.ajax({
            type: "post",
            url: url,
            data: req,
            // dataType: "json",
            success: function (res) {
                if (res.code == 200) {
                    window.localStorage.setItem("token", res.data.id);
                    window.localStorage.setItem("user", JSON.stringify(res.data));
                    window.location.href = $tool.getResUrl() + "/web/index.html";
                }else{
                    layer.msg(res.data, {time:500})
                }
            }
        });
        return false;
    });

});
